<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of socket_client_helper
 *
 * @author Administrator
 */
class Socket_post {
    public $CI;
    public function __construct() {
        
    }
    /*
     * 发送一条消息给语言系统
     * @param string msg 发送的消息
     * @param string identifier 身份识别码 告诉系统 是谁在给跟他讲话
     */
    static public function speak($msg,$identifier)
    {
        get_instance()->load->library('socket_client');
        get_instance()->load->config('speak',true);
        get_instance()->socket_client->set_address(get_instance()->config->item('speak_service_ip','speak'));
        get_instance()->socket_client->set_port(get_instance()->config->item('speak_service_port','speak'));
        $post_data = json_encode(array('msg'=>urlencode(trim($msg)),'number'=>$identifier));
        get_instance()->socket_client->set_socket_message($post_data);
        get_instance()->socket_client->set_socket_message_len(strlen($post_data));
        $data = mb_convert_encoding(get_instance()->socket_client->init(),'utf-8','auto');
        return urldecode($data);
    }
    
    /*
     * 发送一条短信
     */
    public function sms($sms)
    {
        get_instance()->load->library('socket_client');
        get_instance()->load->config('sms',true);
        get_instance()->socket_client->set_address(get_instance()->config->item('sms_service_ip','sms'));
        get_instance()->socket_client->set_port(get_instance()->config->item('sms_service_port','sms'));
        get_instance()->socket_client->set_socket_message(json_encode(array('sms'=>urlencode($sms),'number'=>'13511255367')));
        return $data = $this->socket_client->init();
    }
}